var express = require("express");
var router = express.Router();

// 导入用户路由处理函数
const {
  getArticle,
  deleteArticle,
  addArticle,
  uploadPic,
  getSingleArticle,
  updateArticle,
  updatePic,
} = require("../handleRouter/article");

// 导入multer包
const multer = require("multer");
// 文件存储位置
const upload = multer({ dest: "public/images/uploads/article_cover" });

/**
 * 获取所有文章信息
 */
router.get("/getArticle", getArticle);
/**
 * 获取单个文章信息
 */
router.get("/getSingleArt/:id", getSingleArticle);

/**
 * 添加文章图片
 */
router.post("/uploadPic/:id", upload.single("coverPic"), uploadPic);
/**
 * 更新文章图片
 */
router.put("/updatePic/:id", upload.single("coverPic"), updatePic);
/**
 * 添加文章
 */
router.post("/add", addArticle);
/**
 * 修改文章
 */
router.put("/update/:id", updateArticle);
/**
 * 删除文章
 */
router.delete("/deleted", deleteArticle);

// 导出路由对象
module.exports = router;
